package com.yi.mall.seckill.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yi.mall.common.model.seckill.SeckillActivity;
import com.yi.mall.seckill.mapper.SeckillActivityMapper;
import com.yi.mall.seckill.service.ISeckillActivityService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SeckillActivityServiceImpl extends ServiceImpl<SeckillActivityMapper, SeckillActivity> implements ISeckillActivityService {
    @Override
    public List<SeckillActivity> listActivity() {
        LambdaQueryChainWrapper<SeckillActivity> wrapper = new LambdaQueryChainWrapper<>(baseMapper);
        List<SeckillActivity> list = wrapper
                // 展示未结束的活动
                .gt(SeckillActivity::getEndTime, LocalDateTime.now())
                .orderByAsc(SeckillActivity::getStartTime)
                .last("limit 5") // 最多显示5条
                .list();
        return list;
    }
    @Override
    public List<SeckillActivity> listAllByToday() {
        LambdaQueryChainWrapper<SeckillActivity> wrapper = new LambdaQueryChainWrapper<>(baseMapper);
        List<SeckillActivity> list = wrapper
                .between(SeckillActivity::getStartTime,
                        LocalDateTime.now(), LocalDateTime.now().plusDays(1))
                .list();
        return list;
    }
}
